#ifndef VIEWER_H
#define VIEWER_H

#include <thread>
#include <pangolin/pangolin.h>
#include "common.h"
#include "frame.h"
#include "map.h"

namespace myslam{
    
/**
 * 可视化
 */
class viewer
{
public:
    EIGEN_MAKE_ALIGNED_OPERATOR_NEW;
    typedef std::shared_ptr<viewer> Ptr;
    viewer();
    void SetMap(Map::Ptr map) {map_=map;}
    
    void Close();
    
    //增加一个当前帧
    void AddCurrentFrame(Frame::Ptr current_frame);
    
    //更新地图
    void UpdateMap();
    
private:
    void ThreadLoop();
    
    void DrawFrame(Frame::Ptr frame,const float*color);
    
    void DrawMapPoints();
    
    void FollowCurrentFrame(pangolin::OpenGlRenderState &vis_camera);
     
    //plot the features in current frame into an image
    cv::Mat PlotFrameImage();
    
    Frame:;Ptr current_frame_=nullptr;
    Map::Ptr map_=nullptr;
    
    std::thread viewer_thread_;
    bool viewer_running_=true;
    
    std::unordered_map<unsigned long, Frame::Ptr> active_keyframes_;
    std::unordered_map<unsigned long, MapPoint::Ptr> active_landnmarks_;
    bool map_updated_=false;
    
    std::mutex view_data_mutex_;
};
} // myslam

#endif // VIEWER_H
